<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>欢迎来到德莱联盟</h1>
</body>
<script>
    document.cookie = 'name=赵子龙';
    console.log(document.cookie);
    /**
     * [封装方法]
     */
    /**
     * [setCookie 设置cookie]
     * [key value t 键 值 时间(秒)]
     */
    // function setCookie(key, value, t) {
    //     var oDate = new Date();
    //     oDate.setDate(oDate.getDate() + t);
    //     document.cookie = key + "=" + value + "; expires=" + oDate.toDateString();
    // }
    const xhr = new XMLHttpRequest();
    setTimeout(() => {
       
        xhr.open('post', 'http://localhost:3000/admin/login', true);
        xhr.withCredentials = true;
        xhr.send()

        fetch('http://localhost:3000/admin/login', {
            method: 'post',
            headers: { 'Content-Type': 'application/json; charset=utf-8' },
            body: JSON.stringify({
                username: 'admin',
                password: 12345
            }),
            credentials: 'include'
        }).then(res => {
            console.log('正确', res)
            return res.json();
        })
            .then(res => {
                console.log('正确2', res)
            })
            .catch(err => {
                console.log('错误', err)
            })
    }, 1000)
</script>

</html>